home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-30  |  6.2 KB  |  244 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. /* Lib.c */
  22.  
  23. #include <externs.h>
  24.  
  25. void AVL_SHOW_UNIT2(AVL_UNITDT_PTR w)
  26. {
  27.     int i, first, last, k;    
  28.     short co;
  29.     char msg[100];
  30.  
  31.     k = avl_cur_unit / 12;
  32.     first = k * 12;
  33.     last = first + 11;
  34.     if (last >= avl_size) 
  35.         last = avl_size - 1;
  36.  
  37.     
  38.     _settextposition(1,1);
  39.     _outtext("\n\n\n\n\n\n\n\n\n\n\n\n");
  40.     k = 1;
  41.     for(i = first; i <= last; ++i)  {
  42.         _settextposition(k,1);
  43.         if (i == avl_cur_unit)
  44.             co = _settextcolor(avl_men_ready);
  45.         else
  46.             co = _settextcolor(avl_men_letter);
  47.         sprintf(msg," %s %-6s %c%c/%c%c/%c%c %c%c:%c%c %-38s"
  48.             , (w -> s[i].status  == 'O') ? "Obsolete" : "Active  "
  49.             , (w -> s[i].is_main == 'M') ? "(Main)" : ""
  50.             , w -> s[i].cdate[0] / 10 + '0'
  51.             , w -> s[i].cdate[0] % 10 + '0'
  52.             , w -> s[i].cdate[1] / 10 + '0'
  53.             , w -> s[i].cdate[1] % 10 + '0'
  54.             , w -> s[i].cdate[2] / 10 + '0'
  55.             , w -> s[i].cdate[2] % 10 + '0'
  56.             , w -> s[i].cdate[3] / 10 + '0'
  57.             , w -> s[i].cdate[3] % 10 + '0'
  58.             , w -> s[i].cdate[4] / 10 + '0'
  59.             , w -> s[i].cdate[4] % 10 + '0'
  60.             , w -> s[i].fu
  61.             );
  62.         _outtext(msg);
  63.         ++k;
  64.         }
  65.     _settextcolor(co);
  66. }
  67.                 
  68. void AVL_UNIT2(AVL_UNITDT_PTR w)
  69. {
  70.     int x;
  71.     int r;
  72.     int no = 0;
  73.     int ch, cols = 80, rows;
  74.     AVL_WIN_PTR hw, hw2;
  75.     r = w -> ns;
  76.     if (r < 12)
  77.            rows = r;
  78.     else 
  79.         rows = 12;
  80.     avl_size = r;
  81.     avl_cur_unit = 0;
  82.  
  83.     hw2 = AVL_MAKE_WINDOW("",18,55,18+5,55+24,avl_wnd_bk_color,avl_wnd_color);
  84.     _outtext(" Use the arrow keys to\n");
  85.     _outtext(" go  over  the  units.\n");
  86.     _outtext("\n");
  87.     _outtext(" Press ESC to  cancel.");
  88.  
  89.     hw = AVL_MAKE_WINDOW(" Library's Contents ",4,1,rows+6,80,avl_wnd_bk_color,avl_wnd_color);
  90.  
  91.     while ( 1 )  {
  92.         AVL_SHOW_UNIT2(w);
  93.         ch = getch();
  94.         if (ch == 0 || ch == 0xE0) {
  95.             ch = getch();
  96.             switch( ch ) {
  97.                    case 73 : /* Page Up */ 
  98.                        avl_cur_unit -= rows;
  99.                        if (avl_cur_unit < 0)  
  100.                         avl_cur_unit = avl_size - 1;
  101.                        break;
  102.                    case 81 : /* Page Down */ 
  103.                        avl_cur_unit += rows;
  104.                        if (avl_cur_unit >= avl_size)
  105.                            avl_cur_unit = 0;
  106.                        break;
  107.                    case 72 : /* Up */ 
  108.                        if (--avl_cur_unit < 0)  
  109.                     avl_cur_unit = avl_size - 1;
  110.                        break;
  111.                    case 80 : /* Down */ 
  112.                        if (++avl_cur_unit >= avl_size)
  113.                            avl_cur_unit = 0;
  114.                        break;
  115.                    default : putchar(7); break;
  116.                    }
  117.             continue;
  118.             }
  119.         if (ch == 27)  {
  120.             AVL_DEL_WINDOW(hw);
  121.             AVL_DEL_WINDOW(hw2);
  122.             return;
  123.             }
  124.         putch(7);
  125.         continue;
  126.         }
  127. }            
  128.  
  129.                                 
  130. void  AVL_LIB_SELECT(AVL_UNITDT_PTR w)
  131. {
  132.     short rows, cols;
  133.     int i;
  134.     char msg[50];
  135.  
  136.     for(i = 0; i < w -> ns; ++i)  
  137.         if (!strcmp(w -> s[i].fu,"subprogram DUMMY")) {
  138.             AVL_DELETE_ONE(i,w);
  139.             --i;
  140.             continue;
  141.             }
  142. }
  143.  
  144. void AVL_MAKE_UNIT_DATE(AVL_UNITDT_PTR w)
  145. {
  146.     FILE *fp, *fopen();
  147.     char status[20];
  148.     char type[20];
  149.     char date[20];
  150.     char timex[20];
  151.     char unit[60];
  152.     char line[128];
  153.     int i, j, k;
  154.     w -> ns = 0;
  155.     fp = fopen("avllib.$$$","r");
  156.     k = 0;
  157.     if (fp == NULL)  
  158.         return;
  159.     if (fgets(line,127,fp) == NULL)  return;
  160.     do {
  161.         if (fgets(line,127,fp) == NULL)  {
  162.             if (feof(fp)) break;
  163.             AVL_ERROR("Error reading library. You should make a new library.");
  164.             fclose(fp);
  165.             return;
  166.             }
  167.         if (line[0] == 13) continue;
  168.         if (line[0] == 10) continue;
  169.         if (line[0] == '\n') continue;
  170.         if (strlen(line) < 1) continue;
  171.         for(i = j = 0; line[i] != ' '; ++i, ++j)
  172.             status[j] = line[i];
  173.         status[j] = '\0';
  174.         i = 11;
  175.         if (line[i] != ' ')  {
  176.             for(j = 0; line[i] != ' '; ++i, ++j)
  177.                 type[j] = line[i];
  178.             type[j] = '\0';
  179.             }
  180.         else strcpy(type,"  ");
  181.         i = 21;
  182.         for(j = 0; line[i] != ' '; ++i, ++j)
  183.             date[j] = line[i];
  184.         date[j] = '\0';
  185.         i = 30;
  186.         for(j = 0; line[i] != ' '; ++i, ++j)
  187.             timex[j] = line[i];
  188.         timex[j] = '\0';
  189.         i = 37;
  190.         for(j = 0; i < strlen(line); ++i, ++j)
  191.             unit[j] = line[i];
  192.         if (unit[j - 1] == '\n') --j;
  193.         unit[j] = '\0';
  194.         w -> s[k].status = status[0];
  195.         w -> s[k].is_main = type[1];
  196.         w -> s[k].cdate[0] = (date[0] - '0') * 10 + date[1] - '0';
  197.         w -> s[k].cdate[1] = (date[3] - '0') * 10 + date[4] - '0';
  198.         w -> s[k].cdate[2] = (date[6] - '0') * 10 + date[7] - '0';
  199.         w -> s[k].cdate[3] = (timex[0] - '0') * 10 + timex[1] - '0';
  200.         w -> s[k].cdate[4] = (timex[3] - '0') * 10 + timex[4] - '0';
  201.         strcpy(w -> s[k].fu,unit);
  202.         ++k;
  203.         } while (!feof(fp));
  204.     w -> ns = k;
  205.     fclose(fp);
  206. }
  207.  
  208.         
  209. void AVL_LIST_LIB()
  210. {
  211. /*    AVL_EDIT_WINDOW_PTR w;  */
  212.     AVL_WIN_PTR temp;
  213.     AVL_UNITDT w;
  214.     char msg[100];
  215.     char *bunit;
  216.     char *opts[17];
  217.     int cmd_ret_code, i;
  218.     FILE *fp, *fopen();
  219.     avl_blank_line[0] = '\0';
  220. /*    w = &avl_windows[avl_window];  */
  221.     w.ns = 0;
  222.     opts[0] = "Adalib2";
  223.     opts[1] = "-l";
  224.     opts[2] = avl_dir_library;
  225.     opts[3] = NULL;
  226.     temp = AVL_MAKE_WINDOW(" List Library ",5,1,9,80,avl_wnd_bk_color,avl_wnd_color);
  227.     _outtext("  Searching library. Please, wait a moment...\n");
  228.     if (AVL_EX_UNIT("ADALIB2", opts))  {
  229.         AVL_DEL_WINDOW(temp);
  230.         msg[0] = '\0';
  231.         AVL_MAKE_UNIT_DATE(&w);
  232.         if (w.ns > 0)  {
  233.             AVL_LIB_SELECT(&w);
  234.             if (w.ns != 0)  
  235.                 AVL_UNIT2(&w);
  236.             else
  237.                 AVL_ERROR("Library empty");
  238.             }            
  239.         else 
  240.             AVL_ERROR("Library empty");
  241.         }
  242.     avl_open_error_file = 0;
  243. }
  244.  
  245.